<?php
require_once realpath(dirname(__FILE__).'/../../app/init.php');
require_once 'AIR2_DBManager.php';
AIR2_DBManager::init();

/**
 * Uses doctrine to drop tables (for which we have models)
 */
$conn = AIR2_DBManager::get_master_connection();
$tbls = $conn->fetchColumn('show tables', array(), 0);
echo " > Dropping ".count($tbls)." tables in the database ....";

try {
    $conn->execute('SET FOREIGN_KEY_CHECKS = 0');
    foreach($tbls as $tbl) {
        try {
            $conn->execute('drop table '.$tbl);
        } catch (Doctrine_Exception $e) {
            error_log("ERROR! - ".$e->getMessage());
            exit(1);
        }
    }
    $conn->execute('SET FOREIGN_KEY_CHECKS = 1');
} catch (Doctrine_Exception $e) {
    error_log("ERROR! - ".$e->getMessage());
    exit(1);
}
echo "done!\n";

?>
